#include "SwitchRail.h"
#include "RemoteControl.h"

/* CONSTRUCTOR */
SwitchRail::SwitchRail(SwitchRailListener* switchRailListener, SwitchRailData switchRailData)
{
  m_listener = switchRailListener;
  m_id = switchRailData.getId();
  m_switch = new Switch(this, switchRailData.getSwitchPort());
  m_LED = new LED(switchRailData.getLEDPort());
  m_LED->turnON();    // Led ON
}

/* METHODES */
/**
* \brief Processing for switch position evolution
* \param state
* \return none
*/
void SwitchRail::switchPositionChanged(boolean state)
{
  m_LED->turnOFF();    // Led OFF
  if (state == true)
  {
    m_listener->switchRailHasChanged(m_id, 0xFF);
  }
  else
  {
    m_listener->switchRailHasChanged(m_id, 0x00);
  }
}

/**
* \brief Processing for switch rail command accepted
* \param none
* \return none
*/
void SwitchRail::switchRailCommandAccepted()
{
  m_LED->turnON();    // Led ON
}

/**
* \brief Processing for switch rail command delayed
* \param none
* \return none
*/
void SwitchRail::switchRailCommandDelayed()
{
  m_LED->blink(500);    // Led blink
}

/**
* \brief Get switch rail Id
* \param none
* \return id
*/
byte SwitchRail::getId()
{
  return m_id;
}
